package com.jdk.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKProxy {

    public static <T> T getProxy(Class<T> object){
        Class clz = object.getClass();
        return (T)Proxy.newProxyInstance(object.getClassLoader(),
                new Class[]{object}, new JDKInvocationHandler());
    }

}

class JDKInvocationHandler implements InvocationHandler{
    private Person person;

    JDKInvocationHandler(){
        person = new XiaoMing();
    }

    public void before(){

    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("JDKproxy.........");
        return method.invoke(this.person, args);
    }

    public void after(){

    }
}
